package com.yl.auth.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yl.auth.model.entity.*;
import com.yl.auth.service.*;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author L
 * @datetime 2023/7/25 11:56
 * @description 类对象
 */
@RequestMapping("/admin/yanglao/jigouduanxiaochenxu")
@Api(tags = "机构端小程序")
@RestController
public class JiGouDuanXiaoChengXuController {

    @Resource
    private QianZaiKeHuService qianZaiKeHuService;
    @Resource
    private LaorenService laorenService;
    @Resource
    private JiaShuService jiaShuService;
    @Resource
    private XingZhengChaFangService xingZhengChaFangService;
    @Resource
    private XingZhengChaFangXiangQingService xingZhengChaFangXiangQingService;
    @Resource
    private TouSuJianYiService touSuJianYiService;
    @Resource
    private HuLiDengJiBianGengService huLiDengJiBianGengService;
    @ApiOperation("全查潜在客户")
    @GetMapping("/findAllQianZai")
    public Result findAllQianZai(){
        List<QianZaiKeHu> list = qianZaiKeHuService.list();
        for (QianZaiKeHu qianZaiKeHu : list) {
            Long laorenId = qianZaiKeHu.getLaorenId();
            Laoren laoren = laorenService.getById(laorenId);
            qianZaiKeHu.setLaoren(laoren);
        }
        return Result.ok(list);
    }
    @ApiOperation("潜在客户展示")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id){
        QianZaiKeHu qianZaiKeHu = qianZaiKeHuService.getById(id);
        Long laorenId = qianZaiKeHu.getLaorenId();
        Laoren laoren = laorenService.getById(laorenId);
        qianZaiKeHu.setLaoren(laoren);
        return Result.ok(qianZaiKeHu);
    }
    @ApiOperation(value = "新增潜在客户")
    @PostMapping("/insert")
    public Result insert(@RequestBody QianZaiKeHu qianZaiKeHu){
        //新增老人信息
        Laoren laoren = qianZaiKeHu.getLaoren();
        laorenService.save(laoren);
        //新增潜在客户
        qianZaiKeHu.setLaorenId(laoren.getId());
        qianZaiKeHu.setCreateTime(new Date());
        qianZaiKeHuService.save(qianZaiKeHu);
        return Result.ok();
    }

    @ApiOperation("新增家属信息")
    @PostMapping("/saveJiaShu")
    public Result saveJiaShu(@RequestBody JiaShu jiaShu){
        jiaShuService.save(jiaShu);
        return Result.ok();
    }

    @ApiOperation("行政查房信息查询")
    @GetMapping("/findAll")
    public Result findAll(){
        List<XingZhengChaFang> list = xingZhengChaFangService.list();
        LambdaQueryWrapper<XingZhengChaFangXiangQing> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        for (XingZhengChaFang xingZhengChaFang : list) {
            lambdaQueryWrapper.eq(XingZhengChaFangXiangQing::getXid,xingZhengChaFang.getId());
            XingZhengChaFangXiangQing xingZhengChaFangXiangQing = xingZhengChaFangXiangQingService.getOne(lambdaQueryWrapper);
            xingZhengChaFang.setXingZhengChaFangXiangQing(xingZhengChaFangXiangQing);
        }
        return Result.ok(list);
    }

    @ApiOperation("新增行政查房")
    @PostMapping("/save")
    public Result save(@RequestBody XingZhengChaFangXiangQing xingZhengChaFangXiangQing,XingZhengChaFang xingZhengChaFang){
        xingZhengChaFangService.save(xingZhengChaFang);
        xingZhengChaFangXiangQingService.save(xingZhengChaFangXiangQing);
        return Result.ok();
    }

    @ApiOperation("投诉建议查询")
    @GetMapping("/findAllTouSu")
    public Result findAllTouSu(){
        List<TouSuJianYi> list = touSuJianYiService.list();
        return Result.ok(list);
    }

    @ApiOperation("根据id查询指定的投诉建议详情")
    @GetMapping("/getByIdTouSu/{id}")
    public Result getByIdTouSu(@PathVariable Integer id){
        TouSuJianYi touSuJianYi = touSuJianYiService.getById(id);
        return Result.ok(touSuJianYi);
    }


    @ApiOperation("护理等级变更申请全查")
    @GetMapping("/findAllChuangWei")
    public Result findAllChuangWei(){
        List<HuLiDengJiBianGeng> list = huLiDengJiBianGengService.findAll();
        return Result.ok(list);
    }
//
//    @ApiOperation("护理等级变更申请根据id查看详情")
}
